package com.jereh.topnews.demo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.jereh.topnews.R;

public class OptionMenuActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_option_menu);
    }

    /**
     * 设置菜单
     * @param menu
     * @return
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        //创建一个菜单
        menu.add(Menu.NONE,R.id.menu_refresh,0,"刷新");
        menu.add(Menu.NONE,R.id.menu_browser,2,"用浏览器打开");
        menu.add(Menu.NONE,R.id.menu_link,1,"复制链接");
        menu.add(Menu.NONE,R.id.menu_link,3,"复制链接");
        menu.add(Menu.NONE,R.id.menu_link,4,"复制链接");
        menu.add(Menu.NONE,R.id.menu_link,5,"复制链接");
        menu.add(Menu.NONE,R.id.menu_link,6,"复制链接");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_refresh:
                Toast.makeText(OptionMenuActivity.this, "刷新成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.menu_link:
                Toast.makeText(OptionMenuActivity.this, "复制连接成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.menu_browser:
                Toast.makeText(OptionMenuActivity.this, "跳转到浏览器成功", Toast.LENGTH_SHORT).show();
                break;
        }
        return false;
    }
}
